nethackfandomcom-20200214-history
Source:Prop.h
Below is the full text to include/prop.h from the source code of NetHack 3.4.3. To link to a particular line, write [[prop.h#line123]], for example. This header file defines one unique integer constant for each property in the game. This file also defines struct prop; the game uses this structure to track the source of each property of the hero, whether that source is intrinsic or extrinsic. Top of file 1. /* SCCS Id: @(#)prop.h 3.4 1999/07/07 */ 2. /* Copyright © 1989 Mike Threepoint */ 3. /* NetHack may be freely redistributed. See license for details. */ 4. 5. #ifndef PROP_H 6. #define PROP_H 7. Property constants For each property that the hero may have, the header file here defines a unique integer constant. These constants serve as array indexes to the u.uprops array defined at . These constants count up from one to LAST_PROP. (NetHack does not have a property zero, but arrays in the C language do start at zero. Thus u.uprops0 exists but NetHack does not use it.) Some types of objects convey an extrinsic property, declared in objects.c using these integer constants. For example, the ring of free action conveys FREE_ACTION. Note that monsters (other than the hero) do not use these integer constants; they use the the monster flags defined in monflag.h. For example, the hero has a TELEPORT_CONTROL property, but monsters have an M1_TPORT_CNTRL flag. However, if a monster wears something that conveys an extrinsic property, worn.c will try to handle the situation. 8. /*** What the properties are ***/ 9. #define FIRE_RES 1 10. #define COLD_RES 2 11. #define SLEEP_RES 3 12. #define DISINT_RES 4 13. #define SHOCK_RES 5 14. #define POISON_RES 6 15. #define ACID_RES 7 16. #define STONE_RES 8 17. /* note: for the first eight properties, MR_xxx (1 << (xxx_RES - 1)) */ The equivalence of the *_RES properties and MR_* flags is important, because some corpses convey these resistances to the hero, and because some armor (such as dragon scales) can convey these resistances to monsters. Except NetHack lacks anything to convey between STONE_RES and MR_STONE. 18. #define ADORNED 9 19. #define REGENERATION 10 20. #define SEARCHING 11 21. #define SEE_INVIS 12 22. #define INVIS 13 23. #define TELEPORT 14 24. #define TELEPORT_CONTROL 15 25. #define POLYMORPH 16 26. #define POLYMORPH_CONTROL 17 27. #define LEVITATION 18 28. #define STEALTH 19 29. #define AGGRAVATE_MONSTER 20 30. #define CONFLICT 21 31. #define PROTECTION 22 32. #define PROT_FROM_SHAPE_CHANGERS 23 33. #define WARNING 24 34. #define TELEPAT 25 35. #define FAST 26 36. #define STUNNED 27 37. #define CONFUSION 28 38. #define SICK 29 39. #define BLINDED 30 40. #define SLEEPING 31 41. #define WOUNDED_LEGS 32 42. #define STONED 33 43. #define STRANGLED 34 44. #define HALLUC 35 45. #define HALLUC_RES 36 46. #define FUMBLING 37 47. #define JUMPING 38 48. #define WWALKING 39 49. #define HUNGER 40 50. #define GLIB 41 51. #define REFLECTING 42 52. #define LIFESAVED 43 53. #define ANTIMAGIC 44 54. #define DISPLACED 45 55. #define CLAIRVOYANT 46 56. #define VOMITING 47 57. #define ENERGY_REGENERATION 48 58. #define MAGICAL_BREATHING 49 59. #define HALF_SPDAM 50 60. #define HALF_PHDAM 51 61. #define SICK_RES 52 62. #define DRAIN_RES 53 63. #define WARN_UNDEAD 54 64. #define INVULNERABLE 55 65. #define FREE_ACTION 56 66. #define SWIMMING 57 67. #define SLIMED 58 68. #define FIXED_ABIL 59 69. #define FLYING 60 70. #define UNCHANGING 61 71. #define PASSES_WALLS 62 72. #define SLOW_DIGESTION 63 73. #define INFRAVISION 64 74. #define WARN_OF_MON 65 75. #define DETECT_MONSTERS 66 76. #define LAST_PROP (DETECT_MONSTERS) 77. One can use the LAST_PROP constant to write a loop that iterates through all of the properties, as in . The invocation property of an artifact may be one of the properties above; in that case, invoking that artifact will toggle that property on or off. Some artifacts have a special invocation that does not correspond to any properties of this hero; these extra invocation properties, defined at , do count up from LAST_PROP+1. struct prop The field u.uprops is an array of struct prop. This structure contains three long fields: extrinsic, blocked, intrinsic. For example, the u.upropsPOISON_RES.extrinsic field refers to sources of extrinsic poison resistance, such as the amulet versus poison, the ring of poison resistance, or the green dragon scale mail. The u.upropsPOISON_RES.intrinsic field refers to sources of intrinsic poison resistance, such as by being a Barbarian or by eating something that conveys poison resistance. 78. /*** Where the properties come from ***/ 79. /* Definitions were moved here from obj.h and you.h */ 80. struct prop { extrinsic 81. /*** Properties conveyed by objects ***/ 82. long extrinsic; 83. /* Armor */ 84. # define W_ARM 0x00000001L /* Body armor */ 85. # define W_ARMC 0x00000002L /* Cloak */ 86. # define W_ARMH 0x00000004L /* Helmet/hat */ 87. # define W_ARMS 0x00000008L /* Shield */ 88. # define W_ARMG 0x00000010L /* Gloves/gauntlets */ 89. # define W_ARMF 0x00000020L /* Footwear */ 90. #ifdef TOURIST 91. # define W_ARMU 0x00000040L /* Undershirt */ 92. # define W_ARMOR (W_ARM | W_ARMC | W_ARMH | W_ARMS | W_ARMG | W_ARMF | W_ARMU) 93. #else 94. # define W_ARMOR (W_ARM | W_ARMC | W_ARMH | W_ARMS | W_ARMG | W_ARMF) 95. #endif 96. /* Weapons and artifacts */ 97. # define W_WEP 0x00000100L /* Wielded weapon */ 98. # define W_QUIVER 0x00000200L /* Quiver for (f)iring ammo */ 99. # define W_SWAPWEP 0x00000400L /* Secondary weapon */ 100. # define W_ART 0x00001000L /* Carrying artifact (not really worn) */ 101. # define W_ARTI 0x00002000L /* Invoked artifact (not really worn) */ 102. /* Amulets, rings, tools, and other items */ 103. # define W_AMUL 0x00010000L /* Amulet */ 104. # define W_RINGL 0x00020000L /* Left ring */ 105. # define W_RINGR 0x00040000L /* Right ring */ 106. # define W_RING (W_RINGL | W_RINGR) 107. # define W_TOOL 0x00080000L /* Eyewear */ 108. #ifdef STEED 109. # define W_SADDLE 0x00100000L /* KMH -- For riding monsters */ 110. #endif 111. # define W_BALL 0x00200000L /* Punishment ball */ 112. # define W_CHAIN 0x00400000L /* Punishment chain */ 113. 114. /*** Property is blocked by an object ***/ Each W_* flag represents a slot for worn objects; the extrinsic field uses these flags to indicate possible sources. For example, u.upropsPOLYMORPH & W_RINGL would indicate that the ring on the hero's left finger provides polymorphitis. However, NetHack uses the W_* flags in other places too: * in the owornmask field of struct obj ( ), to indicate how that object is worn. Are you wearing your speed boots on your feet, or wielding them in your hand? * in the misc_worn_check field of struct monst ( ), to check whether a monster has an object in each worn slot. A dwarf steps on a rock trap, does the dwarf wear a helm? You might set the W_QUIVER or W_SWAPWEP field in an owornmask field, but not in a extrinsics field, because quivered ammunition and alternate weapons should never provide extrinsics. blocked 115. long blocked; /* Same assignments as extrinsic */ 116. The blocked field also uses the W_* flags. In NetHack 3.4.3, only two properties may ever become blocked: * clairvoyance, blocked by wearing a cornuthaum, unless your role is Wizard * invisibility, blocked by wearing a mummy wrapping NetHack 3.4.3 contains code to allow objects to block stealth, but there are no objects in the game that do this. (In SLASH'EM, if you are a hobbit, then you block stealth by wearing any footwear except elven boots.) The w_blocks macro (at ) controls which object blocks which property. The blocking of any other property is unimplemented. For example, suppose that you wanted to add a "cloak of flammability" that blocks fire resistance. You would have to add the new cloak to the w_blocks. At this point, the cloak would set u.upropsFIRE_RES.blocked & W_ARMC, but it would have no effect. You would also have to add BFire_resistance macro to youprop.h, and change Fire_resistance so that it checks !BFire_resistance. You would also have to make other fixes; what happens at when a player wearing a cloak of flammability eats something that conveys fire resistance? intrinsic 117. /*** Timeouts, permanent properties, and other flags ***/ 118. long intrinsic; 119. /* Timed properties */ 120. # define TIMEOUT 0x00ffffffL /* Up to 16 million turns */ 121. /* Permanent properties */ 122. # define FROMEXPER 0x01000000L /* Gain/lose with experience, for role */ 123. # define FROMRACE 0x02000000L /* Gain/lose with experience, for race */ 124. # define FROMOUTSIDE 0x04000000L /* By corpses, prayer, thrones, etc. */ 125. # define INTRINSIC (FROMOUTSIDE|FROMRACE|FROMEXPER) 126. /* Control flags */ 127. # define I_SPECIAL 0x10000000L /* Property is controllable */ 128. }; 129. The arrays of struct innate at control which properties that you will gain FROMEXPER or FROMRACE. Other permanent intrinsics are FROMOUTSIDE. Temporary intrinsics use TIMEOUT. Intrinsics from polymorphing into a monster are not stored here. Instead, you must check the monster flags of the youmonst.data monster type. To set a temporary intrinsic, use the incr_itimeout function in potion.c. For example, incr_itimeout(&u.upropsFAST.intrinsic, 100) would grant intrinsic speed for 100 more turns. The I_SPECIAL constant has only two uses in NetHack. * When you quaff a blessed potion of levitation, then u.upropsLEVITATION.intrinsic & I_SPECIAL indicates that you may land at will. * When you wear dragon scales or dragon scale mail and polymorph into a dragon, then uskin->owornmask & I_SPECIAL indicates that the game will restore your armor when you return to normal form. Because of this feature, the I_SPECIAL flag must be distinct from the W_* flags. Definitions for backwards compatibility 130. /*** Definitions for backwards compatibility ***/ 131. #define LEFT_RING W_RINGL 132. #define RIGHT_RING W_RINGR 133. #define LEFT_SIDE LEFT_RING 134. #define RIGHT_SIDE RIGHT_RING 135. #define BOTH_SIDES (LEFT_SIDE | RIGHT_SIDE) 136. #define WORN_ARMOR W_ARM 137. #define WORN_CLOAK W_ARMC 138. #define WORN_HELMET W_ARMH 139. #define WORN_SHIELD W_ARMS 140. #define WORN_GLOVES W_ARMG 141. #define WORN_BOOTS W_ARMF 142. #define WORN_AMUL W_AMUL 143. #define WORN_BLINDF W_TOOL 144. #ifdef TOURIST 145. #define WORN_SHIRT W_ARMU 146. #endif 147. 148. #endif /* PROP_H */ These older names of the W_* flags exist because of how the source code has evolved. NetHack 3.4.3 still uses W_AMUL in some places and WORN_AMUL in other places. In NetHack 3.2.0, the definitions of the W_* flags appear underneath the declaration of the owornmask field at . The definitions of the WORN_* flags appear within the declaration of struct prop at , though they already have the same values. NetHack 3.3.0 moves these definitions to NetHack 3.3.0/prop.h and adds the "backwards compatibility" comment. Related source files Properties appear throughout the source code, but especially in these places: * youprop.h contains several important macros (HPoison_resistance, EPoison_resistance, Poison_resistance) to test if the player has a property as an intrinsic or extrinsic. * begins code that handles intrinsics conveyed by eating corpses. * Conveyance of extrinsics: ** worn.c contains functions (especially setworn and setnotworn) that enable or disable extrinsics as the hero wears or takes off armor. It also tries to handle monsters wearing items that convey extrinsics. ** set_artifact_intrinsic in artifact.c handles extrinsics from artifacts. ** objects.c and artilist.h define objects that convey extrinsics. * Temporary intrinsics: ** begins functions (chiefly incr_itimeout) to handle temporary intrinsics. ** (within the nh_timeout function) begins the loop that decrements the timeout and possibly disables the temporary intrinsic. Category:source code